//监狱、看守所录入操作按钮控制
function autoOperateJyKss(e) {
    var s = "";
    s += '&nbsp;<a class="mini-button mini-button-primary"  onclick="tobaseinfoedit()"  >&nbsp;&nbsp;编辑&nbsp;&nbsp;</a>&nbsp'
    s += '&nbsp;<a class="mini-button mini-button-danger"  onclick="remove1()"  >&nbsp;&nbsp;删除&nbsp;&nbsp;</a>&nbsp'
    return s;
}

//社矫中心录入操作按钮控制
function autoOperateSqjz(e) {
    var s = "";
    s += '&nbsp;<a class="mini-button mini-button-info"  onclick="tosjbaseinfolook()"  >&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp'
    s += '&nbsp;<a class="mini-button mini-button-primary"  onclick="toSjbaseinfoedit()"  >&nbsp;&nbsp;编辑&nbsp;&nbsp;</a>&nbsp'
    s += '&nbsp;<a class="mini-button mini-button-danger"  onclick="remove1()"  >&nbsp;&nbsp;删除&nbsp;&nbsp;</a>&nbsp'
    return s;
}

//司法厅待比对列表操作按钮控制
function autoOperateDbd(e) {
    var s = "";
    s += '&nbsp;<a class="mini-button mini-button-info"  onclick="tobaseinfolook()"  >&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp'
    s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="sfthcsb()"  >&nbsp;&nbsp;执行比对&nbsp;&nbsp;</a>&nbsp'
    return s;
}

//二次核查成功操作按钮控制
function autoOperateSecondHcSuccess(e) {
    var s = "";
    s += '&nbsp;<a class="mini-button mini-button-info"  onclick="tobaseinfolook()"  >&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp'
    return s;
}

/**
 * 待核查列表 - 动态控制核查中列表操作按钮 - 工作台操作
 * @param e
 * @returns {string}
 */
function autoOperate(e) {
    var record = e.value;
    var arr = record.split("@");
    var priAddr = arr[0];
    var hjType = arr[1];
    var level = arr[2];
    var s = "";
    if(level == "01" || level == "02" || level == "05") {
        if (hjType == "02") {//查不清户籍 转入原侦查机关所在地司法所
            s += '&nbsp;<a class="mini-button mini-button-warning" onclick="zryzcjg()"  >&nbsp;&nbsp;转入原侦查机关&nbsp;&nbsp;</a>&nbsp';
        } else if (hjType == "01" && priAddr == "04") {
            s += '&nbsp;<a class="mini-button mini-button-info"  onclick="tobaseinfolook()"  >&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp'
        } else {
            s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="fqhc()"  >&nbsp;&nbsp;发起核查&nbsp;&nbsp;</a>&nbsp';
        }
        s += '&nbsp;<a class="mini-button mini-button-primary" onclick="tobaseinfoedit()"  >&nbsp;&nbsp;编辑&nbsp;&nbsp;</a>&nbsp';
        return s;
    }
    s += '&nbsp;<a class="mini-button mini-button-info"  onclick="tobaseinfolook()"  >&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp';
    return s;
}

/**
 * 批量导入-操作
 * @param e
 * @returns {string}
 */
function autoOperateExcelImport(e) {
    var record = e.value;
    var s = "";
    if (record == "解析成功") {
        //查不清户籍 转入原侦查机关所在地司法所
        s += '&nbsp;<a class="mini-button mini-button-info"  onclick="tobaseinfolookexcel()"  >&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp'
        s += '&nbsp;<a class="mini-button mini-button-danger"  onclick="remove2()"  >&nbsp;&nbsp;删除&nbsp;&nbsp;</a>&nbsp'
    } else if (record == "解析失败") {
        s += '&nbsp;<a class="mini-button mini-button-info"  onclick="tobaseinfolookexcel()"  >&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp'
        s += '&nbsp;<a class="mini-button mini-button-primary" onclick="tobaseinfoeditexcel()"  >&nbsp;&nbsp;编辑&nbsp;&nbsp;</a>&nbsp'
        s += '&nbsp;<a class="mini-button mini-button-danger"  onclick="remove2()"  >&nbsp;&nbsp;删除&nbsp;&nbsp;</a>&nbsp'
    } else if (record == "入库成功") {
        s += '&nbsp;<a class="mini-button mini-button-info"  onclick="tobaseinfolookexcel()"  >&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp'
    } else {
        s += '&nbsp;<a class="mini-button mini-button-info"  onclick="tobaseinfolookexcel()"  >&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp'
        s += '&nbsp;<a class="mini-button mini-button-danger"  onclick="remove2()"  >&nbsp;&nbsp;删除&nbsp;&nbsp;</a>&nbsp'
    }
    return s;
}

/**
 * 核查中列表 - 动态控制核查中列表操作按钮(需要按照，不同的角色进行分配)
 * @param e
 * @returns {string}
 */
function autoOperateChecking(e) {
    var record = e.value;
    var arr = record.split("@");
    var level = arr[0];
    var hjType = arr[1];
    var failurenum = arr[2];
    var pstate = arr[3];
    var receiveType = arr[4];
    var pushState = arr[5];
    var s = "";
    s += '&nbsp;<a class="mini-button mini-button-info"  onclick="tobaseinfolook()"  >&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp';
    if (level == "01" || level == "02" || level == "05") {
        if ((failurenum == '0' || failurenum == '1' || failurenum == '2') && pushState == "0") {
            //监狱核查中列表，撤回按钮
            s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="chhc()"  >&nbsp;&nbsp;撤回&nbsp;&nbsp;</a>&nbsp';
        }
        // 监狱/看守所/社矫回执司法所按钮
        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="hz_jy()"  >&nbsp;&nbsp;联系司法所&nbsp;&nbsp;</a>&nbsp';
        s += '&nbsp;<a class="mini-button mini-button-success"  onclick="exportfile()"  >&nbsp;&nbsp;导出&nbsp;&nbsp;</a>&nbsp';
    } else if (level == "03") {
        // 湖南个性化看守所对接,增加签收按钮
        // 司法所签收按钮
        if (receiveType == "0") { // 条件,司法所未进行签收时展示签收按钮,签收后展示
            s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="sfsqs()"  >&nbsp;&nbsp;签收&nbsp;&nbsp;</a>&nbsp';
        } else if (receiveType == "1") {
            if (hjType == '01') {
                if ((failurenum == '0' || failurenum == '1')) {
                    //户籍完整人员
                    s += '&nbsp;<a class="mini-button mini-button-primary"  onclick="tobaseinfolookOrEdit()"  >&nbsp;&nbsp;编辑&nbsp;&nbsp;</a>&nbsp';
                }
                s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="zxhc()"  >&nbsp;&nbsp;执行核查&nbsp;&nbsp;</a>&nbsp';
            } else if (hjType == '02') {
                //查不清户籍人员
                s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="sfsjs()"  >&nbsp;&nbsp;执行核查&nbsp;&nbsp;</a>&nbsp';
            }
        } else {
            //司法所核查中列表：查看，编辑（部分信息），执行核查（hjType==01），司法所接收（hjType==02）
            if ("" == receiveType) {
                if (hjType == '01') {
                    if ((failurenum == '0' || failurenum == '1')) {
                        //户籍完整人员
                        s += '&nbsp;<a class="mini-button mini-button-primary"  onclick="tobaseinfolookOrEdit()"  >&nbsp;&nbsp;编辑&nbsp;&nbsp;</a>&nbsp';
                    }
                    // 司法所回执监狱/社矫/看守所按钮
                    if (pstate == '5'){
                        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="hz_sfs()"  >&nbsp;&nbsp;联系监狱&nbsp;&nbsp;</a>&nbsp';
                    }else if (pstate == '7'){
                        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="hz_sfs()"  >&nbsp;&nbsp;联系社矫中心&nbsp;&nbsp;</a>&nbsp';
                    }else if (pstate == '3'){
                        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="hz_sfs()"  >&nbsp;&nbsp;联系看守所&nbsp;&nbsp;</a>&nbsp';
                    }else{
                        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="hz_sfs()"  >&nbsp;&nbsp;联系监狱&nbsp;&nbsp;</a>&nbsp';
                    }
                    s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="zxhc()"  >&nbsp;&nbsp;执行核查&nbsp;&nbsp;</a>&nbsp';
                } else if (hjType == '02') {
                    //查不清户籍人员
                    s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="sfsjs()"  >&nbsp;&nbsp;执行核查&nbsp;&nbsp;</a>&nbsp';
                    // 司法所回执监狱/社矫/看守所按钮
                    if (pstate == '5'){
                        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="hz_sfs()"  >&nbsp;&nbsp;联系监狱&nbsp;&nbsp;</a>&nbsp';
                    }else if (pstate == '7'){
                        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="hz_sfs()"  >&nbsp;&nbsp;联系社矫中心&nbsp;&nbsp;</a>&nbsp';
                    }else if (pstate == '3'){
                        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="hz_sfs()"  >&nbsp;&nbsp;联系看守所&nbsp;&nbsp;</a>&nbsp';
                    }else{
                        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="hz_sfs()"  >&nbsp;&nbsp;联系监狱&nbsp;&nbsp;</a>&nbsp';
                    }
                }
            }
        }
        s += '&nbsp;<a class="mini-button mini-button-success"  onclick="exportfile()"  >&nbsp;&nbsp;导出&nbsp;&nbsp;</a>&nbsp';
    }else if (level == "07" || level == "08" || level == "06") {
        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="huizhi()"  >&nbsp;&nbsp;回执&nbsp;&nbsp;</a>&nbsp';
    }
    return s;
}

// 动态核查成功操作列表
function autoSuccessOperateChecking(e) {
    var record = e.value;
    var arr = record.split("@");
    var level = arr[0];
    var pstate = arr[3];
    var p = arr[7];
    var s = "";
    if (p.search("A") != -1 || p.search("B") != -1) {
        s += '&nbsp;<a class="mini-button mini-button-primary"  onclick="leveltobaseinfoedit(' + level + ')"  >&nbsp;&nbsp;编辑&nbsp;&nbsp;</a>&nbsp';
    }
    s += '&nbsp;<a class="mini-button mini-button-info"  onclick="tobaseinfolook()"  >&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp';
    s += '&nbsp;<a class="mini-button mini-button-success"  onclick="exportfiles()"  >&nbsp;&nbsp;导出&nbsp;&nbsp;</a>&nbsp';
    // 核查成功-司法所回执监狱/社矫/看守所按钮
    if (level == "03") {
        if (pstate == '5'){
            s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="hz_sfs()"  >&nbsp;&nbsp;联系监狱&nbsp;&nbsp;</a>&nbsp';
        }else if (pstate == '7'){
            s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="hz_sfs()"  >&nbsp;&nbsp;联系社矫中心&nbsp;&nbsp;</a>&nbsp';
        }else if (pstate == '3'){
            s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="hz_sfs()"  >&nbsp;&nbsp;联系看守所&nbsp;&nbsp;</a>&nbsp';
        }else{
            s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="hz_sfs()"  >&nbsp;&nbsp;联系监狱&nbsp;&nbsp;</a>&nbsp';
        }
    } else if (level == "01" || level == "02" || level == "05") {
        // 监狱核查成功显示联系司法所
        // 监狱/看守所/社矫回执司法所按钮
        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="hz_jy()"  >&nbsp;&nbsp;联系司法所&nbsp;&nbsp;</a>&nbsp';
    }else if (level == "08"|| level == "07" || level == "06"){
        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="huizhi()"  >&nbsp;&nbsp;回执&nbsp;&nbsp;</a>&nbsp';
    }

    return s;
}

/**
 * 待办工作列表操作
 */
function processingAutoOperate(e) {
    var record = e.value;
    var arr = record.split("@");
    var level = arr[0];
    var pushState = arr[1];
    // 户籍地为空,由司法局直接推送
    var nativevill = arr[2];
    var s = "";
    if ((level == "08" && pushState == "1") || (level == "08" && nativevill == "1") || (level == "07" && pushState == "2") || (level == "06" && pushState == "3")) {
        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="doHandle()"  >&nbsp;&nbsp;办理&nbsp;&nbsp;</a>&nbsp';
    }
    /*s += '&nbsp;<a class="mini-button mini-button-success"  onclick="toProcess()">&nbsp;&nbsp;流程过程&nbsp;&nbsp;</a>&nbsp';*/
    s += '&nbsp;<a class="mini-button mini-button-info"  onclick="tobaseinfolook()">&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp';
    //回执按钮
    s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="huizhi()">&nbsp;&nbsp;回执&nbsp;&nbsp;</a>&nbsp';
    return s;
}

/**
 * 已办工作列表操作
 */
function doneOperation() {
    var s = "";
    s += '&nbsp;<a class="mini-button mini-button-success"  onclick="toDownDetails()">&nbsp;&nbsp;办理详情&nbsp;&nbsp;</a>&nbsp';
    s += '&nbsp;<a class="mini-button mini-button-info"  onclick="tobaseinfolook()">&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp';
    return s;
}

//区县司法局/地市司法局/司法厅代办页面 回执
function huizhi(){
    // 查出的那些个数据   row.prinum
    var row = grid.getSelected();
    var record = row.processingOperate;
    var arr = record.split("@");
    var level = arr[0];
    var pstate = arr[4];
    var xjrctId = arr[3];
    var pstateTitle;
    if(pstate == '5' || pstate == '6'){
        pstateTitle = '联系监狱';
    }else if(pstate == '7' || pstate == '8'){
        pstateTitle = '联系社教中心';
    }else if(pstate == '3' || pstate == '4'){
        pstateTitle = '联系看守所';
    }else {
        pstateTitle = '回执';
    }
    if (pstate == '2' || pstate == '1') {
        mini.alert("该人员为司法所补录人员,不能回执");
    }else if (level == "08") {
        commonEdit("/azbj/baseinfo/hc/hzsfj?priNum=" + row.prinum + "&xjrctId=" + xjrctId, pstateTitle, null, '52%', '50%', true, false, true, callback);
        //区县司法局
    } else if (level == "07") {
        commonEdit("/azbj/baseinfo/hc/hzdssfj?priNum=" + row.prinum + "&xjrctId=" + xjrctId, pstateTitle, null, '52%', '50%', true, false, true, callback);
        //地市司法局
    } else if (level == "06") {
        commonEdit("/azbj/baseinfo/hc/hzsft?priNum=" + row.prinum + "&xjrctId=" + xjrctId, pstateTitle, null, '52%', '50%', true, false, true, callback);
    }

    function callback(){
        grid.reload();
    }
}

//导出核查信息函
function exportfile() {
    var row = grid.getSelected();
    if (row) {
        window.location.href = encodeURI("/azbj/azbjgl/doc/export?priNum=" + row.prinum + "&type=1");
    } else {
        mini.alert("请选中一条记录");
    }
}

//核查成功导出核查信息函和核查信息回执单
function exportfiles() {
    var row = grid.getSelected();
    if (row) {
        mini.open({
            url: "/azbj/azbjgl/doc/exportfiles?priNum=" + row.prinum,
            title: "文件导出", width: '380px', height: '180px',
            allowResize: false,
            onload: function () {
            },
            ondestroy: function (action) {
                grid.reload();
            }
        });
    } else {
        alert("请至少选择一条数据！");
    }
}

// 发起批量核查
function plhc() {
    var rows = grid.getSelecteds();
    if (rows.length <= 0) {
        mini.alert("请勾选要发起核查的户籍完整的条目");
        return;
    }
    var prinums = [];
    var i = 0;
    var count = 0;
    for (j = 0, len = rows.length; j < len; j++) {
        if (rows[j].hjType != '02' && rows[j].nativeName != '非大陆籍') {
            prinums[i] = rows[j].prinum;
            i++;
        } else {
            count++;
        }
    }
    // 判断是否在转监或户籍迁移过程中
    $.ajax({
        type: "get",
        url: "/azbj/transfer/fqqy/getTransferRecord?1=1&priNums=" + prinums,
        dataType: "json",
        success: function (data) {
            if (data.code == '1') {
                mini.confirm("您一共选择:" + rows.length + "条数据，其中可发起核查:" + prinums.length + "条,将跳过:" + count + "条户籍不完整等数据",
                    "确定？",
                    function aaa(action) {
                        if (action == "ok") {
                            if (prinums.length <= 0) {
                            } else if (prinums.length == 1) {
                                var row = rows[0];
                                commonEdit("/azbj/verification-first/view?prinum=" + row.prinum + "&pname=" + row.pname + "&sex=" + row.sex + "&nativeName=" + row.nativeName
                                    + "&idnum=" + row.idnum + "&rjDate=" + row.rjDate + "&cjDate=" + row.cjDate + "&investigate=" + row.investigate + "&hjType=" + row.hjType
                                    , "发起核查", row, 800, 460, true, true, true, callback);

                                function callback() {
                                    grid.reload();
                                }
                            } else {
                                commonEdit("/azbj/verification-first/plview?prinums=" + prinums
                                    , "批量发起核查", null, 800, 500, true, true, true, callback);
                                function callback() {
                                    grid.reload();
                                }
                            }
                        }
                    }
                );
            } else {
                mini.alert("有服刑人员正在数据迁移,请完成迁移后再进行此操作!");
            }
        }
    });
    grid.reload();
}

// 预安置人员信息录入添加 - 跳转弹出框
function toPopup() {
    mini.open({
        url: "/azbj/topopup",
        title: "服刑人员信息录入", width: '68%', height: '80%',
        onload: function () {
        },
        ondestroy: function (action) {
            grid.reload();
        }
    });
}

// 社矫跳转弹出框
function toSjPopup() {
    mini.open({
        url: "/azbj/tosjpopup",
        title: "在矫人员信息录入", width: '68%', height: '80%',
        onload: function () {
        },
        ondestroy: function (action) {
            grid.reload();
        }
    });
}

// 跳转弹出框
function toPopupBu() {
    mini.open({
        url: "/azbj/topopupBu",
        title: "监狱刑满释放人员补录", width: '68%', height: '80%',
        onload: function () {
        },
        ondestroy: function (action) {
            grid.reload();
        }
    });
}

// 跳转弹出框
function toPopupBuJJ() {
    mini.open({
        url: "/sqjz/topopup_bl",
        title: "解矫人员信息补录", width: '68%', height: '80%',
        onload: function () {
        },
        ondestroy: function (action) {
            grid.reload();
        }
    });
}

// 批量导入
function toimport() {
    mini.open({
        url: "/azbj/toimport",
        title: "批量导入服刑人员信息", width: '30%', height: '30%',
        onload: function () {
        },
        ondestroy: function (action) {
            grid.reload();
        }
    });
}

// 保存批量导入的数据
function toSaveImportExcel() {

    $.ajax({
        url: "/azbj/import/baseinfo/checkMainExcelImportData",
        type: 'POST',
        cache: false,
        async: true,
        success: function (result) {
            if (result.code != 1) {
                mini.unmask(document.body);
                mini.alert("请导入模版数据");
                return;
            } else {
                var url = "/azbj/import/baseinfo/saveExcelImportData";
                mini.confirm("确定将列表中导入成功的数据保存到预安置录入页面，此操作不可撤销？",
                    "确定？",
                    function (action) {
                        if (action == "ok") {
                            mini.mask({
                                el: document.body,
                                cls: 'mini-mask-loading',
                                html: '数据保存中，请稍等...'
                            })
                            $.ajax({
                                url: url,
                                type: 'POST',
                                cache: false,
                                async: true,
                                success: function (result) {
                                    if (result.code == 1) {
                                        if (action == "ok") {
                                            mini.unmask(document.body);
                                            mini.alert("保存成功!");
                                            grid.reload();
                                        }
                                    } else if (result.code == 5000) {
                                        mini.unmask(document.body);
                                        mini.alert(result.message);
                                    } else if (result.code == 9004) {
                                        mini.unmask(document.body);
                                        mini.alert(result.message);
                                    } else {
                                        mini.unmask(document.body);
                                        mini.alert("导入失败");
                                    }
                                }
                            });
                        } else {
                            mini.unmask(document.body);
                        }
                    });
            }
        }
    });
}

// 发起核查
function fqhc() {
    var row = grid.getSelected();//获取列表行数据
    if (row.prinum) {
        $.ajax({
            type: "get",
            url: "/azbj/transfer/fqqy/getTransferRecord?1=1&priNums=" + row.prinum,
            dataType: "json",
            success: function (data) {
                if (data.code == '1') {
                    var row = grid.getSelected();
                    if (row.length > 1) {
                        mini.alert("请勾选一条需要发起核查的记录");
                    } else {
                        var url = "/azbj/verification-first/view?prinum=" + row.prinum + "&pname=" +
                            encodeURIComponent(row.pname) + "&sex=" +
                            encodeURIComponent(row.sex) + "&nativeName=" +
                            encodeURIComponent(row.nativeName)
                            + "&idnum=" + row.idnum + "&rjDate=" + row.rjDate + "&cjDate=" + row.cjDate + "&investigate=" + row.investigate + "&hjType=" + row.hjType;
                        commonEdit(url
                            , "发起核查", row, 800, 460, true, true, true, callback);
                        function callback() {
                            grid.reload();
                        }
                    }
                } else {
                    mini.alert("此服刑人员正在数据迁移,请完成迁移后再进行此操作!");
                }
            }
        });
    }
}

// 发起核查申请(监狱第二次发起核查;此次核查需要先到监狱局审批，监狱局同意之后才到司法所，不同意给原因)
function zcfqhc() {
    var row = grid.getSelected();
    if (row.length > 1) {
        mini.alert("请选择一条记录再次发起核查");
    } else {
        var row = grid.getSelected();
        commonEdit("/azbj/verification-zcfqhc/view?prinum=" + row.prinum + "&nativepro=" + row.nativepro + "&nativecity=" + row.nativecity + "&nativecou=" + row.nativecou + "&nativevill=" + row.nativevill + "&nativenum=" + row.nativenum + "&failurenum=" + row.failurenum+"&sex="+row.sex,
            "再次发起核查", row, '60%', '50%', true, true, true, callback);

        function callback() {
            grid.reload();
        }
    }
}

// 二次核查失败，再次发起到原侦查机关所在地司法所，由原侦查机关所在地进行接收
function zryzcjg() {
    var row = grid.getSelected();//获取列表行数据
    if (row.length > 1) {
        mini.alert("请勾选一条需要转入原侦查机关的记录");
    } else {
        var row = grid.getSelected();
        commonEdit("/azbj/verification-zryzcjg/view?prinum=" + row.prinum + "&nativepro=" + row.nativepro + "&nativecity=" + row.nativecity + "&nativecou=" + row.nativecou + "&nativevill=" + row.nativevill + "&nativenum=" + row.nativenum + "&failurenum=" + row.failurenum,
            "转入原侦查机关司法所", row, '60%', '50%', true, true, true, callback);

        function callback() {
            grid.reload();
        }
    }
}

// 撤回核查
function chhc() {
    var row = grid.getSelected();
    $.ajax({
        url: "/azbj/verification/hcstate",
        type: "post",
        data: {prinum: row.prinum, state: 0, _method: "post"},
        success: function (success) {
            if (success.code == 1) {
                mini.alert("撤回成功");
                grid.reload();
            } else {
                mini.alert("非核查中状态,撤回失败");
                grid.reload();
            }
        }
    })
}

/**
 * 执行核查
 */
function zxhc() {
    var row = grid.getSelected();
    commonEdit("/azbj/verification-zxhc/view?id=" + row.id, "执行核查", "", '60%', '65%', true, true, true, callback);

    function callback() {
        grid.reload();
    }
}

/**
 * 查不清户籍接收
 */
function sfsjs() {
    var row = grid.getSelected();
    commonEdit("/azbj/verification-zxhc-js/view?id=" + row.id, "执行核查", row, '60%', '50%', true, true, true, callback);
    function callback() {
        grid.reload();
    }
}

/**
 * 核查失败原因(监狱)
 */
function hcsbyy() {
    var row = grid.getSelected();
    commonEdit("/azbj/verification-hcsb/view?id=" + row.id, "核查失败原因", "", '40%', '45%', true, true, true, null);
}

/**
 * 区县司法局,地市司法局,司法厅办理按钮
 */
function doHandle() {
    var row = grid.getSelected();
    var strs = row.processingOperate;
    var arr = strs.split("@");
    var pstate = arr[4];
    commonEdit("/azbj/verification-handle/view?id=" + row.id + "&pstate=" + pstate, "待办页面", row, '68%', '68%', true, true, true, callback);
    function callback() {
        grid.reload();
    }
}

/**
 * 编辑服刑人员录入的信息
 */
function tobaseinfoedit() {
    var rows = grid.getSelecteds();
    if (rows.length > 1) {
        mini.alert("请勾选一条数据再编辑");

    } else {
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/azbj/baseinfo/editview?prinum=" + row.prinum + "&id=" + row.id,
                title: "编辑服刑人员信息", width: '68%', height: '80%',
                onload: function () {
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        } else {
            alert("请至少选择一条数据！");
        }
    }
}

/**
 * 编辑服刑人员录入的信息excel
 */
function tobaseinfoeditexcel() {
    var rows = grid.getSelecteds();
    if (rows.length > 1) {
        mini.alert("请勾选一条数据再编辑");
    } else {
        var row = grid.getSelected();
        grid.on("beforeselect",function(e){
            if(e.record.successFlag =='2'){
                e.cancel=false;
            }
        })
        if (row) {
            mini.open({
                url: "/azbj/baseinfo/editviewexcel?prinum=" + row.prinum + "&id=" + row.id,
                title: "编辑服刑人员信息", width: '68%', height: '80%',
                onload: function () {
                    grid.on("beforeselect",function(e){
                        if(e.record.successFlag =='2'){
                            e.cancel=true;
                        }
                    })
                },
                ondestroy: function (action) {
                    grid.on("beforeselect",function(e){
                        if(e.record.successFlag =='2'){
                            e.cancel=true;
                        }
                    })
                    grid.reload();
                }
            });
        } else {
            alert("请至少选择一条数据！");
            grid.on("beforeselect",function(e){
                if(e.record.successFlag =='2'){
                    e.cancel=false;
                }
            })
        }
    }
}

/**
 * 编辑在矫人员录入的信息
 */
function toSjbaseinfoedit() {
    var rows = grid.getSelecteds();
    if (rows.length > 1) {
        mini.alert("请勾选一条数据再编辑");

    } else {
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/azbj/baseinfo/sjeditview?prinum=" + row.prinum + "&id=" + row.id,
                title: "编辑在矫人员信息", width: '68%', height: '80%',
                onload: function () {
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        } else {
            alert("请至少选择一条数据！");
        }
    }
}
function leveltobaseinfoedit(e) {
    var rows = grid.getSelecteds();
    var level = e;
    if (rows.length > 1) {
        mini.alert("请勾选一条数据再编辑");
    } else {
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/azbj/success/baseinfo/editview?prinum=" + row.prinum + "&id=" + row.id + "&level=" + level,
                title: "编辑服刑人员信息", width: '68%', height: '80%',
                onload: function () {
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        } else {
            alert("请至少选择一条数据！");
        }
    }
}

function remove1() {
    var row = grid.getSelected();
    if (row) {
        var url = "/azbj/baseinfo/removeinfo?prinum=" + row.prinum;
        mini.confirm("确定删除选中记录？",
            "确定？",
            function (action) {
                if (action == "ok") {
                    $.ajax({
                        url: url,
                        type: 'POST',
                        cache: false,
                        async: false,
                        data: {id: row.id},
                        success: function (text) {
                            mini.alert("操作成功!");
                            grid.reload();
                        }, error: function () {
                            mini.alert("操作失败!");
                        }
                    });
                }
            });
    } else {
        mini.alert("请选中一条记录");
    }
}

function remove2() {
    var row = grid.getSelected();
    if (row) {
        var url = "/azbj/baseinfo/removeinfoexcel?prinum=" + row.prinum;
        mini.confirm("确定删除选中记录？",
            "确定？",
            function (action) {
                if (action == "ok") {
                    $.ajax({
                        url: url,
                        type: 'POST',
                        cache: false,
                        async: false,
                        data: {id: row.id},
                        success: function (text) {
                            mini.alert("操作成功!");
                            grid.reload();
                        }, error: function () {
                            mini.alert("操作失败!");
                        }
                    });
                }
            });
    } else {
        mini.alert("请选中一条记录");
    }
}

//批量删除excel的数据未入库成功的数据
function toDeleteImportExcel(){
    var rows = grid.getSelecteds();
    if (rows.length <= 0) {
        mini.alert("请勾选要删除的数据");
        return;
    }
    var prinums = [];
    var deleteCount = 0;
    for (j = 0, len = rows.length; j < len; j++) {
        if (rows[j].successFlag != '2') {
            prinums[deleteCount] = rows[j].prinum;
            deleteCount++;
        }
    }
    mini.confirm("您一共选择:" + rows.length + "条数据，可删除的数据为:"+prinums.length+"条，是否删除？",
        "确定？",
        function aaa(action) {
            if (action == "ok") {
                var url = "/azbj/baseinfo/removeinfoexcels";
                mini.confirm("确定删除选中记录？",
                    "确定？",
                    function (action) {
                        if (action == "ok") {
                            $.ajax({
                                url: url,
                                type: 'POST',
                                cache: false,
                                async: false,
                                traditional: true,
                                data: {prinumLists:prinums},
                                success: function (text) {
                                    mini.alert("操作成功!");
                                    grid.reload();
                                }, error: function () {
                                    mini.alert("操作失败!");
                                }
                            });
                        }
                    });
            }
        }
    );
    grid.reload();
}

//批量删除 补录信息
function toDeleteImportExcelBl(){
    var rows = grid.getSelecteds();
    if (rows.length <= 0) {
        mini.alert("请勾选要删除的数据");
        return;
    }
    var prinums=[];
    var stopMessage = "帮教信息、安置信息、救助信息、帮扶信息、年鉴信息、双列管信息、安帮信息、户籍迁入迁出信息、走访信息";
    var deleteCount = 0;
    for(i = 0, len = rows.length;i < len;i++){
        if(rows[i].operationStatebl =='1'){
            prinums[deleteCount] = rows[i].prinum;
            deleteCount++;
        }
    }
    if ( prinums.length===0 ) {
        mini.alert("您选择的" + rows.length + "数据中，没有可以删除的数据。请排查删除以下信息后继续。"+ `<br/>` +stopMessage);
        return;
    }
    mini.confirm("您一共选择: " + rows.length + " 条数据，其中可删除的数据为："+prinums.length+" 条，是否删除？",
        "确定？",
        function aaa(action) {
            if (action == "ok") {
                var url = "/azbj/inmates/baseinfo/deleteInfos";
                mini.confirm("确定删除选中记录？",
                    "确定？",
                    function (action) {
                        if (action == "ok") {
                            $.ajax({
                                url: url,
                                type: 'POST',
                                cache: false,
                                async: false,
                                traditional: true,
                                data: {prinumLists:prinums},
                                success: function (response) {
                                    if(response.code=='4000'){
                                        mini.alert("操作失败!");
                                    }else{
                                        mini.alert("操作成功");
                                    }
                                    grid.reload();
                                }, error: function () {
                                    mini.alert("操作失败!");
                                }
                            });
                        }
                    });
            }
        }
    );
    grid.reload();
}

//默认列表
function allInfo() {
    var url = "/azbj/inmates/info/list?listType=100";
    grid.setUrl(url);
    grid.reload();
}

//户籍完整人员
function selectHjwz() {
    var url = "/azbj/inmates/info/list?listType=101";
    grid.setUrl(url);
    grid.reload();
}

//查不清户籍
function selectNoHj() {
    var url = "/azbj/inmates/info/list?listType=102";
    grid.setUrl(url);
    grid.reload();
}

//有未成年子女
function juvenileInfo() {
    var url = "/azbj/inmates/info/list?listType=103";
    grid.setUrl(url);
    grid.reload();
}

//无照片或指纹人员
function nomutiInfo() {
    var url = "/azbj/inmates/info/list?listType=104";
    grid.setUrl(url);
    grid.reload();
}

//姓名重复人员
function nameRepetitionInfo() {
    var url = "/azbj/inmates/info/list?listType=105";
    grid.setUrl(url);
    grid.reload();
}

// { 'id': '1', 'text': '全部' }
// { 'id': '2', 'text': '户籍完整人员' }
// { 'id': '3', 'text': '查不清户籍人员' }
// { 'id': '4', 'text': '有未成年子女人员' }
// { 'id': '5', 'text': '无照片或指纹人员' }
// { 'id': '6', 'text': '姓名重复人员' }
function kuaiSelect() {
    var val = mini.get("kuaisu").getValue();
    if (val == "1") {
        allInfo();
    } else if (val == "2") {
        selectHjwz();
    } else if (val == "3") {
        selectNoHj();
    } else if (val == "4") {
        juvenileInfo();
    } else if (val == "5") {
        nomutiInfo();
    } else if (val == "6") {
        //姓名重复人员
        nameRepetitionInfo();
    } else {
        allInfo();
    }
}

//格式化日期函数
function onDateRenderer(e) {
    var date = new Date(e.value);
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
    var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
    var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
    var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
    var formatTime = Y + M + D + h + m + s;
    return formatTime;
}

// 已办详情页面
function toDownDetails(){
    var rows = grid.getSelecteds();
    if (rows.length > 1) {
        mini.alert("请勾选一条数据再查看");
    } else {
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/azbj/baseinfo/toDownDetailsView?id=" + row.id +"&tsId="+row.tsId,
                title: "已办详情页面查看", width: '68%', height: '80%',
                onload: function () {
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        } else {
            alert("请至少选择一条数据！");
        }
    }
}
// 跳转到服刑人员查看界面
function tobaseinfolook() {
    var rows = grid.getSelecteds();
    if (rows.length > 1) {
        mini.alert("请勾选一条数据再查看");
    } else {
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/azbj/baseinfo/tolookview?priNum=" + row.prinum + "&id=" + row.id,
                title: "预安置人员信息查看", width: '68%', height: '80%',
                onload: function () {
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        } else {
            alert("请至少选择一条数据！");
        }
    }
}

// 跳转司法所回执监狱页面 -- 监狱 司法所 区县局 地市局 司法厅核查失败回执通用
function hz_sfs(){
    //得到页面的行数
    var row = grid.getSelected();
    var record = row.operateStateHc;
    var arr = record.split("@");
    var level = arr[0];
    var pstate = arr[3];
    var xjrctId = arr[6];
    if (level == '03') {
        if (pstate == '5') {
            commonEdit("/azbj/baseinfo/hc/hzsfs?priNum=" + row.prinum + "&xjrctId=" + xjrctId, "联系监狱", null, '52%', '50%', true, false, true, callback);
        } else if (pstate == '7') {
            commonEdit("/azbj/baseinfo/hc/hzsfs?priNum=" + row.prinum + "&xjrctId=" + xjrctId, "联系社矫中心", null, '52%', '50%', true, false, true, callback);
        } else if (pstate == '3') {
            commonEdit("/azbj/baseinfo/hc/hzsfs?priNum=" + row.prinum + "&xjrctId=" + xjrctId, "联系看守所", null, '52%', '50%', true, false, true, callback);
        } else if (pstate == '2' || pstate == '1') {
            mini.alert("该人员为司法所补录人员,不能回执");
        }else {
            commonEdit("/azbj/baseinfo/hc/hzsfs?priNum=" + row.prinum + "&xjrctId=" + xjrctId, "回执", null, '52%', '50%', true, false, true, callback);
        }
    } else if (level == '01' || level == '05' || level == '02') {
        //监狱、看守所、社矫 回执司法所按钮
        commonEdit("/azbj/baseinfo/hc/hzjy?priNum=" + row.prinum + "&xjrctId=" + xjrctId, "联系司法所", null, '52%', '50%', true, false, true, callback);
    } else if (level == '07' || level == '06' || level == '08') {
        //在区县、地市、司法厅每个地方点击回执--根据level跳到不同的回执页面
        huizhi();
    }

    function callback() {
        grid.reload();
    }
}

// 跳转监狱回执司法所页面
function hz_jy(){
    //得到页面的行数
    var row = grid.getSelected();
    var record = row.operateStateHc;
    var arr = record.split("@");
    var xjrctId = arr[6];
    var pstate = arr[3];
    //司法所补录的监狱、社矫人员
    if (pstate == '2' || pstate == '1'){
        mini.alert("该人员为司法所补录人员,不能回执");
    }else {
        commonEdit("/azbj/baseinfo/hc/hzjy?priNum=" + row.prinum + "&xjrctId=" + xjrctId, "联系司法所", null, '52%', '60%', true, false, true, callback);
    }

    function callback() {
        grid.reload();
    }
}

// 跳转查看流程过程页面
function toProcess() {
    var rows = grid.getSelecteds();
    if (rows.length > 1) {
        mini.alert("请勾选一条数据再查看");
    } else {
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/azbj/baseinfo/toProcess?priNum=" + row.prinum,
                title: "流程过程", width: '50%', height: '50%',
                onload: function () {
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        } else {
            alert("请至少选择一条数据！");
        }
    }
}

// 跳转到服刑人员查看界面excel
function tobaseinfolookexcel() {
    var rows = grid.getSelecteds();
    if (rows.length > 1) {
        mini.alert("请勾选一条数据再查看");
    }
    var row = grid.getSelected();
    if (row) {
            mini.open({
                url: "/azbj/baseinfo/tolookviewexcel?priNum=" + row.prinum + "&id=" + row.id,
                title: "预安置人员信息查看", width: '68%', height: '80%',
                onload: function () {
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
    } else {
            alert("请至少选择一条数据！");
    }

}

// 跳转到在矫人员查看界面
function tosjbaseinfolook() {
    var rows = grid.getSelecteds();
    if (rows.length > 1) {
        mini.alert("请勾选一条数据再查看");
    } else {
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/azbj/baseinfo/tosjlookview?priNum=" + row.prinum + "&id=" + row.id,
                title: "预安置人员信息查看", width: '68%', height: '80%',
                onload: function () {
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        } else {
            alert("请至少选择一条数据！");
        }
    }
}

// 司法所用户能编辑,其他用户只能查看基本信息
function tobaseinfolookOrEdit() {
    var row = grid.getSelected();
    if (row) {
        mini.open({
            url: "/azbj/baseinfo/tolookviewOrEdit?prinum=" + row.prinum + "&id=" + row.id,
            title: "预安置人员信息", width: '68%', height: '80%',
            onload: function () {
            },
            ondestroy: function (action) {
                grid.reload();
            }
        });
    } else {
        alert("请至少选择一条数据！");
    }
}

/**
 * 下载批量导入模板
 */
function downloadExcelTemplate() {
    mini.open({
        url: "/azbj/import/excelimport/importfiles",
        title: "模版下载", width: '300px', height: '180px',
        allowResize: false,
        onload: function () {
        },
        ondestroy: function (action) {
            grid.reload();
        }
    });
}

/**
 * 导入日期和批次号联动
 * @param e
 */
function onDateChange(e) {
    var date = mini.getByName("date");
    var uuid = mini.getByName("uuid");
    var date1 = date.getValue();
    var date2 = new Date(date1)
    var dateTime = date2.getFullYear() + checkTime(date2.getMonth() + 1) + checkTime(date2.getDate());
    uuid.setValue("");
    var url = "/azbj/import/search/code/selectUuidByDate?1=1&date=" + dateTime;
    uuid.setUrl(url);
    uuid.select(0);
}

function checkTime(i) {
    if (i < 10) {
        i = '0' + i
    }
    return i
}

/**
 * 湖南看守所个性化 - 签收
 */
function sfsqs() {
    var row = grid.getSelected();
    if (row) {
        var url = "/azbj/verification/signFor";
        mini.confirm("确认签收此服刑人员？",
            "确定？",
            function (action) {
                if (action == "ok") {
                    $.ajax({
                        url: url,
                        type: 'POST',
                        cache: false,
                        async: false,
                        data: {priNum: row.prinum, type: "1"},
                        success: function (data) {
                            if(data.code == '1') {
                                mini.alert("签收成功!");
                            } else if (data.code == 5599) {
                                mini.alert(data.message);
                            } else {
                                mini.alert("签收失败!");
                            }
                            grid.reload();
                        }, error: function () {
                            mini.alert("操作失败!");
                        }
                    });
                }
            });
    } else {
        mini.alert("请选中一条记录");
    }
}
/**
 * 安置帮教管理 人员信息补录 信息录入 列表 操作集合（编辑 查看 删除）
 * @param e 就是映射字段的值  是安置不是安置的在sql中去区分 1是编辑 3是查看  再连起来
 */
function autoOperateBl(e){
    var record = e.value;
    var s = "";
    s += '&nbsp;<a class="mini-button mini-button-primary" onclick="toBlbaseinfoedit()">&nbsp;&nbsp;编辑&nbsp;&nbsp;</a>&nbsp';
    if (record != "0"){
        s += '&nbsp;<a class="mini-button mini-button-danger" onclick="removeBulu()">&nbsp;&nbsp;删除&nbsp;&nbsp;</a>&nbsp';
    }
    s += '&nbsp;<a class="mini-button mini-button-info" onclick="toblbaseinfolook()">&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp';
    return s;
}

//删除补录人员信息录入
function removeBulu() {
    var row = grid.getSelected();
    if (row) {
        var url = "/azbj/inmates/baseinfo/deleteInfo?prinum=" + row.prinum;
        mini.confirm("确定删除选中记录,确定之后将删除该服刑人员所有有关信息？",
            "确定？",
            function (action) {
                if (action == "ok") {
                    $.ajax({
                        url: url,
                        type: 'POST',
                        cache: false,
                        async: false,
                        data: {id: row.id},
                        success: function (text) {
                            mini.alert("操作成功!");
                            grid.reload();
                        }, error: function () {
                            mini.alert("操作失败!");
                        }
                    });
                }
            });
    } else {
        mini.alert("请选中一条记录");
    }
}

/*编辑补录人员信息录入*/
function toBlbaseinfoedit() {
    var rows = grid.getSelecteds();
    if (rows.length > 1) {
        mini.alert("请勾选一条数据再编辑");

    }
    var row = grid.getSelected();
    if (row) {
        mini.open({
            url: "/azbj/baseinfo/editBlview?prinum=" + row.prinum + "&id=" + row.id,
            title: "编辑服刑人员信息", width: '68%', height: '80%',
            onload: function () {},
            ondestroy: function (action) {
                grid.reload();
            }
        });
    } else {
        alert("请至少选择一条数据！");
    }
}


// 跳转到补录的服刑人员查看界面
function toblbaseinfolook() {
    var rows = grid.getSelecteds();
    if (rows.length > 1) {
        mini.alert("请勾选一条数据再查看");
    }
    var row = grid.getSelected();
    if (row) {
        mini.open({
            url: "/azbj/baseinfo/tobllookview?priNum=" + row.prinum + "&id=" + row.id,
            title: "预安置人员信息查看", width: '68%', height: '80%',
            onload: function () {},
            ondestroy: function (action) {
                grid.reload();
            }
        });
    } else {
        alert("请至少选择一条数据！");
    }
}